package Vue;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;

import javax.swing.JFrame;
import javax.swing.JTabbedPane;

import org.jfree.chart.ChartFactory;
import org.jfree.chart.ChartPanel;
import org.jfree.chart.JFreeChart;
import org.jfree.chart.plot.PlotOrientation;
import org.jfree.data.category.DefaultCategoryDataset;

public class VueStatistiques extends JFrame{

	JTabbedPane tabbedPane;
	public VueStatistiques() {
    	setTitle("Statistiques de la simulation") ;
    	tabbedPane = new JTabbedPane();

		this.setContentPane(tabbedPane);
		this.pack();
    }
    
    public void ajouterGraphiqueSimple(String nomStat, List<Integer> stats)
    {
    	DefaultCategoryDataset line_chart_dataset = new DefaultCategoryDataset();
		Integer i = 0;
    	for (Integer statTour : stats) {
    		line_chart_dataset.addValue(statTour, nomStat, i.toString());
    		i++;
		}

		/* Step -2:Define the JFreeChart object to create line chart */
		JFreeChart lineChartObject = ChartFactory
				.createLineChart(nomStat + " par tours", "Tours", nomStat,
						line_chart_dataset, PlotOrientation.VERTICAL, true,
						true, false);

		// create and display a frame...
		ChartPanel panel = new ChartPanel(lineChartObject);
		tabbedPane.addTab(nomStat, panel);
    }
    
    public void ajouterGraphiqueMultiLigne(String nomStat, Map<String,ArrayList<Integer>> EnsembleStats)
    {
    	DefaultCategoryDataset line_chart_dataset = new DefaultCategoryDataset();
		
    	for (Entry<String,ArrayList<Integer>> e : EnsembleStats.entrySet())
    	{
    		String nomCourbe = e.getKey();
    		List<Integer> stats = e.getValue();
    		Integer i = 0;
	    	for (Integer statTour : stats) {
	    		line_chart_dataset.addValue(statTour, nomCourbe, i.toString());
	    		i++;
	    	}
		}

		/* Step -2:Define the JFreeChart object to create line chart */
		JFreeChart lineChartObject = ChartFactory
				.createLineChart(nomStat + " par tours", "Tours", nomStat,
						line_chart_dataset, PlotOrientation.VERTICAL, true,
						true, false);

		// create and display a frame...
		ChartPanel panel = new ChartPanel(lineChartObject);
		tabbedPane.addTab(nomStat, panel);
    }
}
